package com.gm.wholesale.module.order.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.gm.wholesale.R;
import com.gm.wholesale.module.good.bean.GoodBean;

import java.util.List;

public class ChoiceGoodTagView extends LinearLayout implements View.OnClickListener {

    private TextView goodTagTv1;
    private TextView goodTagTv2;
    private TextView goodTagTv3;

    private OnTagGoodClickListener listener;

    private List<GoodBean> mGoodBeans;

    public interface OnTagGoodClickListener {
        void onTagGoodClick(GoodBean goodBean);
    }

    public ChoiceGoodTagView(Context context) {
        super(context);
        init(context);
    }

    public ChoiceGoodTagView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.view_choice_good_tag, this);
        initView();

    }

    private void initView() {
        goodTagTv1 = findViewById(R.id.goodTagTv1);
        goodTagTv2 = findViewById(R.id.goodTagTv2);
        goodTagTv3 = findViewById(R.id.goodTagTv3);
        goodTagTv1.setOnClickListener(this);
        goodTagTv2.setOnClickListener(this);
        goodTagTv3.setOnClickListener(this);
    }

    public void showView(List<GoodBean> goodBeans, OnTagGoodClickListener listener) {
        this.listener = listener;
        mGoodBeans = goodBeans;
        goodTagTv1.setTag(0);
        goodTagTv2.setTag(1);
        goodTagTv3.setTag(2);
        if (goodBeans.size() == 1) {

            goodTagTv1.setText(goodBeans.get(0).getName());
            goodTagTv1.setVisibility(VISIBLE);
            return;
        }
        if (goodBeans.size() == 2) {
            goodTagTv1.setText(goodBeans.get(0).getName());
            goodTagTv2.setText(goodBeans.get(1).getName());
            goodTagTv1.setVisibility(VISIBLE);
            goodTagTv2.setVisibility(VISIBLE);
            return;
        }
        if (goodBeans.size() >= 3) {
            goodTagTv1.setText(goodBeans.get(0).getName());
            goodTagTv2.setText(goodBeans.get(1).getName());
            goodTagTv3.setText(goodBeans.get(2).getName());
            goodTagTv1.setVisibility(VISIBLE);
            goodTagTv2.setVisibility(VISIBLE);
            goodTagTv3.setVisibility(VISIBLE);
            return;
        }
    }

    @Override
    public void onClick(View view) {
        listener.onTagGoodClick(mGoodBeans.get((Integer) view.getTag()));


    }
}
